#!/bin/bash

# 设置颜色
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

echo -e "${BLUE}=======================================${NC}"
echo -e "${GREEN}智约班车预约系统 - 启动脚本${NC}"
echo -e "${BLUE}=======================================${NC}"

# 检查Docker和Docker Compose是否安装
if command -v docker &> /dev/null && command -v docker-compose &> /dev/null; then
    echo -e "${GREEN}Docker和Docker Compose已安装，使用Docker启动服务...${NC}"
    
    # 停止可能正在运行的容器
    echo -e "${BLUE}停止现有容器...${NC}"
    docker-compose down
    
    # 构建并启动容器
    echo -e "${BLUE}启动新容器...${NC}"
    docker-compose up -d
    
    echo -e "${GREEN}容器启动完成!${NC}"
    echo -e "${BLUE}=======================================${NC}"
    echo -e "${GREEN}服务访问地址:${NC}"
    echo -e "${BLUE}API: http://localhost:8080/api/v1${NC}"
    echo -e "${BLUE}MySQL: localhost:3306${NC}"
    echo -e "${BLUE}Redis: localhost:6379${NC}"
    echo -e "${BLUE}RabbitMQ: http://localhost:15672${NC}"
    echo -e "${BLUE}=======================================${NC}"
    
    # 显示容器状态
    echo -e "${GREEN}容器状态:${NC}"
    docker-compose ps
    
else
    echo -e "${BLUE}Docker或Docker Compose未安装，使用Maven启动服务...${NC}"
    
    # 使用Maven打包
    echo -e "${BLUE}使用Maven打包项目...${NC}"
    ./mvnw clean package -DskipTests
    
    # 启动服务
    echo -e "${BLUE}启动服务...${NC}"
    java -jar target/car-booking-1.0.0.jar
fi 